const { getActionSheet } = require('../../utils/util');
const { getDict } = require('../../utils/dict');
// pages/authentication/components/DefineInput/index.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    placeholder: {
      type: String,
      value: '请输入'
    },
    type: {
      type: String,
      value: 'text'
    },
    errorMsg: {
      type: String,
      observer(newValue) {
        this.setData({ errorMsg: newValue });
      }
    },
    label: {
      type: String,
      value: ''
    },
    dict: { type: String, value: '' }
  },

  /**
   * 组件的初始数据
   */
  data: {
    value: '',
    show: false,
    dictList: []
  },

  /*** 组件的方法列表 */
  methods: {
    onHideErrorMsg() {
      this.setData({
        errorMsg: ''
      });
    },
    async onOpen() {
      const actionsheet = getActionSheet();
      console.log(await getDict(this.properties.dict));
      //  打开弹窗 之前 请求字典项 
      this.setData({  dictList: await getDict(this.properties.dict) }, () => {
        actionsheet.open({ 
          actions: this.data.dictList, 
          success: (res) => {
            this.setData({ value: res.name });
            this.triggerEvent('select', res.code);
          }
        });
      })
    },
  }
})